<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Add extends MY_Controller {

	function __construct() {
		parent::__construct();

		$this->load->helper('url');
		$this->load->helper('form');

		//$this->output->cache(0.5);

	}

	public function index1() {
		$data['title'] = "MyHome - 我的家园";
		$data['heading'] = "MyHome";
		//load->library


		//load->model


		//$data

		$data['title'] =  "New - " . $data['title'];


		//load->view
		$this->load->view('header', $data);
		$this->load->view('new_view', $data);
		$this->load->view('sidebar');
		$this->load->view('footer');
	}

	public function post() {
		$data['title'] = "MyHome - 我的家园";
		$data['heading'] = "MyHome";
		$this->load->helper('typography');

		$this->load->model('Post');
		$this->load->model('MTerm');

		if($this->input->post('submit')) {
			$pid = $this->Post->insert();
			$this->MTerm->insert_relationships($pid);
			redirect('post/' . $pid);
		}

		$data['title'] = "写文章 - ".$data['title'];
		$data['attributes'] = array('class'=>'post', 'id'=>'post');
		$data['list_category'] = $this->MTerm->list_term();
		$data['list_tag'] = $this->MTerm->list_term('tag');

		$this->load->view('header', $data);
		$this->load->view('new_post_view', $data);
		$this->load->view('sidebar');
		$this->load->view('footer');
	}
	public function term() {
		$data['title'] = "MyHome - 我的家园";
		$data['heading'] = "MyHome";
		$this->load->model('MTerm');

		if($this->input->post('submit')) {
			$this->MTerm->insert();
			redirect('new/term');
			/*redirect('category/' . $this->Term->insert());*/
		}
		$data['list'] = $this->MTerm->list_term();

		$data['title'] = "新增分类 - ".$data['title'];
		$data['attributes'] = array('class'=>'term', 'id'=>'term');

		$this->load->view('header', $data);
		$this->load->view('new_term_view', $data);
		$this->load->view('sidebar');
		$this->load->view('footer');
	}


	public function comment() {
		$this->load->model('Comment');
		$this->load->model('Post');
		if($this->input->post('submit')) {
			$this->Comment->insert();
			$this->Post->update_veiws($this->input->post('comment_post_id'),'comment_count');
			redirect('post/' . $this->input->post('comment_post_id'));
		}
	}
}

/* End of file add.php */
/* Location: ./application/controllers/add.php */